package com.bw.services.visit.adapter

import android.widget.ImageView
import android.widget.TextView
import com.bw.lib_base.base.BaseViewModel
import com.bw.services.R
import com.bw.services.databinding.ItemVisitBinding
import com.bw.services.visit.entity.VisitData
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class VisitAdapter :BaseQuickAdapter<VisitData,BaseViewHolder>(R.layout.item_visit){
    lateinit var binding: ItemVisitBinding
    private var dataList: List<VisitData> = emptyList()
    fun setData(newData: List<VisitData>) {
        dataList = newData
        setList(newData) // BaseQuickAdapter自带setList方法，推荐直接用
        notifyDataSetChanged()
    }

    override fun convert(holder: BaseViewHolder, item: VisitData) {
        holder.setText(R.id.visit_time,item.appointmentTime)
        holder.setText(R.id.visit_status,item.visitStatus)
        holder.setText(R.id.visit_name,item.visitorName)
        holder.setText(R.id.visit_phone,item.phoneNumber)
        holder.setText(R.id.visit_reason,"来访事由:${item.purpose}")
        holder.setText(R.id.visit_person,"访问对象:张经理(技术部)")
        val isPark = holder.getView<TextView>(R.id.visit_ispark)
        val tv_status = holder.getView<TextView>(R.id.visit_status)
        if (item.approved==true){
            holder.getView<TextView>(R.id.visit_ispark).text="已申请访客车位:A区-12号"
            isPark.setTextColor(context.getColor(R.color.blue))
            holder.getView<ImageView>(R.id.visit_img).setImageResource(R.drawable.ic_car_blue)
        }else{
            holder.getView<TextView>(R.id.visit_ispark).text="未申请访客车位"
            isPark.setTextColor(context.getColor(R.color.lightgray))
            holder.getView<ImageView>(R.id.visit_img).setImageResource(R.drawable.ic_car_gray)
        }
        if (item.visitStatus=="已通过"){
            tv_status.setTextColor(context.getColor(R.color.visit_status_green))
            tv_status.setBackgroundResource(R.drawable.shape_status)
        }else if (item.visitStatus=="待审核"){
            tv_status.setTextColor(context.getColor(R.color.visit_status_yellow))
            tv_status.setBackgroundResource(R.drawable.shape_status1)
        }else if (item.visitStatus=="驳回"){
            tv_status.setTextColor(context.getColor(R.color.visit_status_gray))
            tv_status.setBackgroundResource(R.drawable.shape_status3)

        }else{
            tv_status.setTextColor(context.getColor(R.color.visit_status_gray))
            tv_status.setBackgroundResource(R.drawable.shape_status3)
        }
    }

}